// 1. 引入接口函数

import { reqGetSearchGoodsInfoData } from '@/api';

// 2. 书写配置项
const state = {
  goodsInfo: {}
};
const actions = {
  // 1. 获取搜索的商品信息
  async getSearchGoodsInfo({ commit }, searchParams) {
    const result = await reqGetSearchGoodsInfoData(searchParams);
    if (result.code === 200) {
      commit('SAVE_SEARCH_GOODS_INFO', result.data);
    } else {
      console.log(result.message);
    }
  }
};
const mutations = {
  // 1. 存储搜索到的商品数据
  SAVE_SEARCH_GOODS_INFO(state, goodsInfo) {
    state.goodsInfo = goodsInfo;
  }
};

// 就相当于是Vuex中的计算属性
const getters = {
  // 1. 商品列表数据
  goodsList(state) {
    return state.goodsInfo.goodsList;
  },
  // 2. 详细属性列表
  attrsList(state) {
    return state.goodsInfo.attrsList;
  },
  // 3. 品牌列表
  trademarkList(state) {
    return state.goodsInfo.trademarkList;
  },
  // 4. 商品的总数量
  total(state) {
    return state.goodsInfo.total;
  }
};

// 3. 导出模块
export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
};
